package com.cross.core;

import java.util.ArrayList;
import java.util.List;

/**
 * 搬运器的一个简单实现
 * 
 * 2009-2-7
 * 
 * @author craziness_stone
 */
public class CollectTractor extends AbstractTractor {
	//收集信息
	private List<String[]> collectResult = new ArrayList<String[]>();
	//收集字段
	private String[] collectFiled;
	public CollectTractor(){
	}
	
	public CollectTractor(Reader<Row> reader, Writer writer, String[] collectFiled) {
		super.reader = reader;
		super.writer = writer;
		this.collectFiled = collectFiled;
	}
	protected void run() throws Exception{
		if(null == reader){
			throw new Exception("没有读取器");
		}
		if(null == writer){
			throw new Exception("没有组装器");
		}
		Row row;
		Header header = reader.getHeader();
		Column column;
		int[] columnNumbers;
		if(collectFiled != null && collectFiled.length>0){
			columnNumbers = new int[collectFiled.length];
			for(int i=0; i<collectFiled.length; i++){
				column = header.getColumn(collectFiled[i]);
				column.getNumber();
			}
		}
		while(reader.hasNext()){
			if(writer.available()){
				row = reader.next();
				writer.write(row);
				
				
				
				
			} else {
				reader.close();
				writer.close();
				break;
			}
		}
	}
}
